import 'package:app_info/info/appsflyer.dart';
import 'package:flutter/material.dart';
import 'package:smartloan_mdc/route/app_routes.dart';
import 'package:smartloan_mdc/utils/common/utils.dart';

// extension on String
extension Img on String {
  Widget appImg({
    double? width,
    double? height,
    BoxFit? fit
  }) {
    return Image.asset("assets/img/$this.png",
        width: width, height: height, fit: fit);
  }
}

extension StringExtension on String {
  Widget sText({
    double fontSize = 14,
    Color? color,
    FontWeight? fontWeight,
    int? maxLines,
    TextOverflow? overflow,
    TextDecoration? decoration,
  }){
    return Text(this,
      style: TextStyle(
        fontSize: fontSize,
        color: color ?? const Color(0xFF333333),
        fontWeight: fontWeight,
        decoration: decoration,
        decorationColor: color ?? const Color(0xFF333333),
      ),
      maxLines: maxLines,
      overflow: overflow,
    );
  }

  void toast({String? pageName}) {
    Utils.showToast(this);
    AppsFlyer().logEvent("toast_${pageName ?? AppRoutes.getCurrentPageName() }_$this");
    debugPrint('toast === $pageName | $this');
  }

}

// extension on Widget
extension WidgetExtension on Widget {
  GestureDetector onPress(Function onTap) {
    return GestureDetector(
      onTap: () { onTap.call(); },
      child: this,
    );
  }

  Widget padding({
    EdgeInsets? padding,
    EdgeInsets? margin,
  }) {
    return Container(
      padding: padding,
      margin: margin,
      child: this,
    );
  }

  Widget decorationBox({
    Color? color,
    double? radius,
    EdgeInsets? padding,
    EdgeInsets? margin,
  }) {
    return Container(
      padding: padding ?? const EdgeInsets.all(0),
      margin: margin ?? const EdgeInsets.all(0),
      decoration: BoxDecoration(
        color: color ?? Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(radius ?? 0)),
      ),
      child: this,
    );
  }

  Widget sizeBox({
    required double width,
    required double height,
  }) {
    return SizedBox(
      width: width,
      height: height,
      child: this,
    );
  }
}

// extension on number
extension ToSizedBox on double {
  Widget hSizedBox() {
    return SizedBox(
      height: this
    );
  }

  Widget wSizedBox() {
    return SizedBox(
      width: this,
    );
  }
}